package view.lyd.com.sectionrecyclerviewdemo;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import listview.activity.ListViewActivity;
import listview.activity.ListViewAddHeadFootActivity;
import listview.activity.TestAddHeadActivity;
import recycleview.activity.ItemDecorationActivity;
import recycleview.activity.RecyclerActivity;
import recycleview.activity.RefreshRecyActivity;

import static view.lyd.com.sectionrecyclerviewdemo.R.id.tv;

/**
 * Created by niudong on 2017/6/15.
 * Tel：18811793194
 * VersionChange：
 * <p>
 */
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    public TextView tv_text;
    private Button button1;
    private Button button2;
    private Button button3, generate_code, lv_test, lv_head_foot, re_view, radar_chart;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);
        initView();
        initListener();

    }

    private void initListener() {
        button1.setOnClickListener(this);
        button2.setOnClickListener(this);
        button3.setOnClickListener(this);
        generate_code.setOnClickListener(this);
        lv_test.setOnClickListener(this);
        lv_head_foot.setOnClickListener(this);
        re_view.setOnClickListener(this);
        radar_chart.setOnClickListener(this);
    }

    private void initView() {
        button1 = (Button) findViewById(R.id.bt1);
        lv_test = (Button) findViewById(R.id.lv_test);
        re_view = (Button) findViewById(R.id.bt_re_view);
        tv_text = (TextView) findViewById(R.id.tv_text);
        button2 = (Button) findViewById(R.id.bt2);
        button3 = (Button) findViewById(R.id.bt3);
        generate_code = (Button) findViewById(R.id.generate_code);
        lv_head_foot = (Button) findViewById(R.id.lv_head_foot);
        radar_chart = (Button) findViewById(R.id.radar_chart);

        String txt = "风险等级综合评分：65  高";
        setLimitRedTextTv(tv_text, txt);

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {

            case R.id.generate_code:
                Intent generateQRCodeIntent = new Intent(MainActivity.this, QRCodeActivity.class);
                startActivityForResult(generateQRCodeIntent, 0);
                break;
            case R.id.bt1:
                Intent intent = new Intent(MainActivity.this, RecyclerActivity.class);
                startActivity(intent);
                break;
            case R.id.bt2:
                Intent intent2 = new Intent(MainActivity.this, ListViewActivity.class);
                startActivity(intent2);
                break;
            case R.id.bt3:
                Intent intent3 = new Intent(MainActivity.this, ItemDecorationActivity.class);
                startActivity(intent3);
                break;

            case R.id.lv_test:
                Intent intent4 = new Intent(MainActivity.this, TestAddHeadActivity.class);
                startActivity(intent4);
                break;
            case R.id.lv_head_foot:
                Intent intent5 = new Intent(MainActivity.this, ListViewAddHeadFootActivity.class);
                startActivity(intent5);
                break;

            case R.id.bt_re_view:
                Intent intent6 = new Intent(MainActivity.this, RefreshRecyActivity.class);
                startActivity(intent6);
                break;

            case R.id.radar_chart:
                Intent intent7 = new Intent(MainActivity.this, RiskLevelActivity.class);
                startActivity(intent7);
                break;
            default:
                break;

        }
    }

    /**
     * 设置风险等级综合评分
     *
     * @param textView View
     * @param textName 风险等级综合评分：48  中
     */
    private void setLimitRedTextTv(TextView textView, String textName) {

        SpannableString builder = new SpannableString(textName);
        int color = getResources().getColor(R.color.colorPrimary);
        builder.setSpan(new ForegroundColorSpan(color), 9, 14, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        textView.setText(builder);
    }
}
